/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.picture.bank.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sys.entity.Post;
import com.jeesite.modules.sys.service.PostService;
import com.jeesite.modules.zx.picture.bank.entity.TpictureBank;
import com.jeesite.modules.zx.picture.bank.service.TpictureBankService;

/**
 * 图片题题库Controller
 * @author zpp
 * @version 2020-03-27
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/picture/bank/tpictureBank")
public class TpictureBankController extends BaseController {

	@Autowired
	private TpictureBankService tpictureBankService;
	@Autowired
	private PostService postService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TpictureBank get(String id, boolean isNewRecord) {
		return tpictureBankService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:view")
	@RequestMapping(value = {"list", ""})
	public String list(TpictureBank tpictureBank, Model model) {
		model.addAttribute("tpictureBank", tpictureBank);
		return "modules/zx/picture/bank/tpictureBankList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TpictureBank> listData(TpictureBank tpictureBank, HttpServletRequest request, HttpServletResponse response) {
		tpictureBank.setPage(new Page<>(request, response));
		Page<TpictureBank> page = tpictureBankService.findPage(tpictureBank);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:view")
	@RequestMapping(value = "form")
	public String form(TpictureBank tpictureBank, Model model) {
		Post post = new Post();
		model.addAttribute("postList", postService.findList(post));
		model.addAttribute("tpictureBank", tpictureBank);
		return "modules/zx/picture/bank/tpictureBankForm";
	}

	/**
	 * 保存图片题题库
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TpictureBank tpictureBank) {
		tpictureBankService.save(tpictureBank);
		return renderResult(Global.TRUE, text("保存图片题题库成功！"));
	}
	
	/**
	 * 停用图片题题库
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TpictureBank tpictureBank) {
		tpictureBank.setStatus(TpictureBank.STATUS_DISABLE);
		tpictureBankService.updateStatus(tpictureBank);
		return renderResult(Global.TRUE, text("停用图片题题库成功"));
	}
	
	/**
	 * 启用图片题题库
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TpictureBank tpictureBank) {
		tpictureBank.setStatus(TpictureBank.STATUS_NORMAL);
		tpictureBankService.updateStatus(tpictureBank);
		return renderResult(Global.TRUE, text("启用图片题题库成功"));
	}
	
	/**
	 * 删除图片题题库
	 */
	@RequiresPermissions("zx:picture:bank:tpictureBank:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TpictureBank tpictureBank) {
		tpictureBankService.delete(tpictureBank);
		return renderResult(Global.TRUE, text("删除图片题题库成功！"));
	}
	
}